package org.example.day20240829Calendar;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CalendarMain {
    public static void main(String[] args) throws ParseException {
        String DateStr = "2024-08-29";

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = simpleDateFormat.parse(DateStr);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        int today = calendar.get(Calendar.DATE);
        calendar.add(Calendar.DATE , -today+1);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) -1;
        if(dayOfWeek == 0){
            dayOfWeek = 7;
        }

        calendar.add(Calendar.MONTH, 1);
        calendar.add(Calendar.DATE,-1);
        int lastDay = calendar.get(Calendar.DATE);

        int count = 1;
        int[] arr = new int[6*7];
        for (int i = dayOfWeek; i < dayOfWeek+lastDay; i++){
            arr[i] = count++;
        }

        System.out.println("一\t二\t三\t四\t五\t六\t日");
        int counter = 0;
        for (int i = 0;i<arr.length; i++){
            if(arr[i] != 0){
                if(arr[i] == today){
                    System.out.print("*");
                }
                System.out.print(arr[i] + "\t");
            }
            else {
                System.out.print(" \t");
            }
            counter++;
            if(counter % 7 == 0){
                System.out.println();
            }
        }
    }
}
